﻿using System;
using System.Collections.Generic;

namespace Borg.Detector
{
    public struct DetectorInfo
    {
        private readonly Uri _origin;
        private readonly Uri _metadata;

        public Uri Origin
        {
            get { return _origin; }
        }

        public Uri Metadata
        {
            get { return _metadata; }
        }

        public DetectorInfo(Uri origin)
        {
            this = new DetectorInfo(origin, origin);
        }

        public DetectorInfo(Uri origin, Uri metadata)
        {
            _origin = origin;
            _metadata = metadata;
        }

        public override string ToString()
        {
            return string.Format("{{Origin={0}, Metadata={1}}}", _origin, _metadata);
        }
    }

    public class DetectorEventArgs
    {
        private readonly IEnumerable<DetectorInfo> _detectorInfos;

        public IEnumerable<DetectorInfo> DetectorInfos
        {
            get { return _detectorInfos; }
        }

        public DetectorEventArgs(IEnumerable<DetectorInfo> detectorInfos)
        {
            _detectorInfos = detectorInfos;
        }
    }

    public delegate void DetectorEventHandler(DetectorEventArgs args);

    [SlotDefinition("Borg.Detector")]
    public interface IDetector
    {
        event DetectorEventHandler Detected;
        event DetectorEventHandler Removed;

        void Start();
    }

    [SlotDefinition("Borg.Analyzer", IsThreadsafe = true)]
    public interface IAnalyzer
    {
        string Id { get; }

        bool Analyze(Uri originUri, Uri metadataUri, TypeBuilder builder, out Contract contract, out Plugin plugin);
        bool Analyze(Uri uri, TypeBuilder builder, out Contract contract, out Plugin plugin);
    }

    public delegate bool SkipPredicate(DetectorInfo detectorInfo, IAnalyzer analyzer);
}
